package com.example.intent;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class FActivity extends Activity {
	private Button bt1;
	private Button bt2;
	private Context mContext;
	private TextView tv;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.factivity);

		/*
		 * 通过点击bt1 跳转 start activity 初始化intend
		 */
		mContext = this;
		bt1 = (Button) findViewById(R.id.button1_first);
		bt2 = (Button) findViewById(R.id.button2_second);
		tv = (TextView) findViewById(R.id.textView1);

		bt1.setOnClickListener(new OnClickListener() {
			/*
			 * (non-Javadoc)
			 * 
			 * @see android.view.View.OnClickListener#onClick(android.view.View)
			 */
			@Override
			/*
			 * 第一个参数 this 第二个 目标文件
			 */
			public void onClick(View v) {
				Intent intent = new Intent(mContext, SActivity.class);
				startActivity(intent);
			}
		});

		bt2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext, SActivity.class);
				/*
				 * 第一个参数是intent 的兑现 第二个是请求标示
				 */

				startActivityForResult(intent, 1);
			}
		});
	}

	/*
	 * requestcode 是请求标识 resultcode 是页面返回的标识 data是第二个页面回传的数据
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == 1 && resultCode == 2) {
			String content = data.getStringExtra("data");
			tv.setText(content);

		}
	}
}
